import type { Module } from 'vuex'
import lkfRequest from '@/services'
import { IRootState } from '../types'
import { IRankList } from './types'
/* 排行store */
const rank: Module<IRankList, IRootState> = {
  namespaced: true,
  state() {
    return {
      rankList: []
    }
  },
  getters: {},
  mutations: {
    getRankListGetter(state, list) {
      for (const item of list) {
        item.coverImgUrl += '?param=200x200'
      }
      state.rankList = list
    }
  },
  actions: {
    /* 请求数据 */
    async getRankListAction({ commit }) {
      const list = await lkfRequest.get({
        url: `toplist`
      })
      commit('getRankListGetter', list.list)
    }
  }
}
export default rank
